package com.ce.pms.custservice.service.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.util.Assert;
import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.common.model.HmDeptDomain;
import com.ce.pms.common.model.SysInfo;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.service.ICodingGeneratorService;
import com.ce.pms.common.service.IOrganizationalStructureService;
import com.ce.pms.common.util.BigDecimalUtil;
import com.ce.pms.custservice.dao.ICustServiceEventDao;
import com.ce.pms.custservice.dao.IDispatchFormDao;
import com.ce.pms.custservice.model.AbstractServiceItem;
import com.ce.pms.custservice.model.CustServiceEventDO;
import com.ce.pms.custservice.model.DispatchFormDO;
import com.ce.pms.custservice.vo.DispatchingVO;
import com.ce.pms.custservice.model.BillDO;
import com.ce.pms.custservice.model.Dispatching;
import com.ce.pms.custservice.model.FeedbackRecord;
import com.ce.pms.custservice.model.LaborItem;
import com.ce.pms.custservice.model.MaterialItem;
import com.ce.pms.custservice.model.SubmitTaskDO;
import com.ce.pms.custservice.service.ICustServChargeService;
import com.ce.pms.custservice.service.IDFormManageService;
import com.ce.pms.custservice.service.IDispatchFormStateMachineService;
import com.ce.pms.custservice.service.ISubmitTaskService;
import com.ce.pms.custservice.vo.AbstractServiceItemVO;
import com.ce.pms.custservice.vo.BillVO;
import com.ce.pms.custservice.vo.DispatchFormQueryVo;
import com.ce.pms.custservice.vo.DispatchFormReportVO;
import com.ce.pms.custservice.vo.DispatchFormSearchVO;
import com.ce.pms.custservice.vo.DispatchFormVO;
import com.ce.pms.custservice.vo.FeedbackRecordVO;
import com.ce.pms.custservice.vo.FeedbackSearchVO;
import com.ce.pms.custservice.vo.LaborItemVO;
import com.ce.pms.custservice.vo.MaterialItemVO;
import com.ce.pms.custservice.vo.ServItemSearchVO;
import com.ce.pms.custservice.vo.SubmitTaskVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.system.custservice.model.EmergencyDegreeDO;
import com.ce.pms.system.custservice.service.IEmergencyDegreeService;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BeanUtil;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.support.Page;

/**
 *
 * 	名称: com.ce.pms.custservice.service.impl.DFormManageServiceImpl <br>
 *  派工单管理业务类
 *
 * @author  付湘辉  <br>
 * Created on： 2008-12-22 <br>
 * @author <br>
 * update on： <br>
 * why: <br>
 */
public class DFormManageServiceImpl extends PmsBaseServiceImpl implements IDFormManageService ,ICEReportDataSetService{
   private ICodingGeneratorService codingGeneratorService;
   private ICustServChargeService custServChargeService;
   private ICustServiceEventDao custServiceEventDao;

   /**
    * 部门名称暂存
 	*/
   private Map<Long, String> deptNameCacheMap;
   private IDispatchFormDao dispatchFormDao;

   /**
    * 派工单状态暂存
 	*/
   private Map<String, String> dispatchFormStateCacheMap;

   private IDispatchFormStateMachineService dispatchFormStateMachineService;

   private IEmergencyDegreeService emergencyDegreeService;

   /**
	 * 员工姓名缓冲，以用户id为key,员工姓名为value
	 */
   @SuppressWarnings("unused")
   private Map<Long, String> hmployeeNameCacheMap;

   private IHouseService houseService;

   private IOrganizationalStructureService organizationalStructureService;

   private ISubmitTaskService submitTaskService;

   /**
    * 功能描述:新增派工单  <br>
    * @param csEventID - 事件ID
    * @param dFormVo
    * @roseuid 49436CAF01F4
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-23  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public DispatchFormVO addDispatchForm(Long csEventID,DispatchFormVO dFormVo) {
		Assert.notNull(dFormVo);
		CustServiceEventDO custEventDo = this.custServiceEventDao.findById(csEventID);
		//检查是否允许新增
		Boolean isAllow = custEventDo.isAllowAddDispatchForm();
		if (!isAllow) {
			throw new BusinessException("custservice:custservice_cannot_adddform_exception",
								BusinessException.WARNING);
		}
		SysInfo sysInfo = super.createInfo(dFormVo.getCreator());
		addOneDispatchForm(csEventID, dFormVo,sysInfo);
		return dFormVo;
	}

   /**
    * 功能描述:反馈登记  <br>
    * @param dispatchFormID - 派工单ID
    * @param feedbackVo - 反馈Vo
    * @roseuid 49436CAF0271
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public FeedbackRecordVO addFeedback(Long dispatchFormID, FeedbackRecordVO feedbackVo) {
	   DispatchFormDO dispatchFormDo = this.dispatchFormDao.findById(dispatchFormID);
	   this.checkIsAllowAddFeedback(dispatchFormID);
	   FeedbackRecord feedback = new FeedbackRecord();
	   SysInfo sysInfo = super.createInfo(feedbackVo.getCreator());
	   feedback.setSysInfo(sysInfo);
	   feedbackVo.setSysDate(sysInfo.getSysDate());
	   //装配DO
	   this.assembleFeedbackRecordV2D(feedbackVo, feedback);
	   //开工时间
	   dispatchFormDo.setStartTime(feedbackVo.getStartTime());
	   //初始状态
	   feedback.initValidity();
	   //新增反馈
	   dispatchFormDo.addFeedback(feedback);
	   //必填项检查
	   checkFeedbackRequiredField(feedback);
	   //更新派工单
	   this.dispatchFormDao.updateObject(dispatchFormDo);

	   //检查
	   this.dispatchFormStateMachineService.decideStatuzWithAddFeedback(dispatchFormDo);
	   if (dispatchFormDo.isDFormComplete()) {
		   dispatchFormDo.setEndTime(feedbackVo.getEndTime());
		   this.submitTaskService.noteDispatchFormComplete(dispatchFormDo.getSubmitTaskDO().getKeyword());
	   }
	   checkStartTimeAndEndTime(dispatchFormDo);

	   feedbackVo.setValidity(feedback.getValidity());
	   feedbackVo.setKeyword(feedback.getKeyword());
	   return feedbackVo;
   }
   
   /**
    * 功能描述: 新增服务项目
    * @param dFormID - 派工单ID
    * @param servItemVo - 服务项目
    * @roseuid 49436CAF02CE
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-17  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public AbstractServiceItemVO addServItem(Long dFormID, AbstractServiceItemVO servItemVo) {
	   DispatchFormDO  dispatchForm = this.dispatchFormDao.findById(dFormID);
	   this.checkDispatchFormAddServItem(dispatchForm);
	   //得到一个实例
	   AbstractServiceItem serviceItem = this.generateItemDOByItemVO(servItemVo);
	   SysInfo sysInfo = super.createInfo(servItemVo.getCreator());
	   servItemVo.setSysDate(sysInfo.getSysDate());
	   //装配
	   this.assembleAbstractServiceItemV2D(servItemVo, serviceItem);
	   serviceItem.setSysInfo(sysInfo);
	   //增加
	   dispatchForm.addServItem(serviceItem);

	   this.dispatchFormDao.updateObject(dispatchForm);
	   //统计金额
	   BigDecimal sumAmt = this.sumServItemFee(dispatchForm);
	   //更新账单
	   this.custServChargeService.noteUpdateBill(dFormID, sumAmt);

	   servItemVo.setKeyword(serviceItem.getKeyword());
	   return servItemVo;
   }
   
   /**
    * 功能描述:检查指定的派工单是否允许增加账单  <br>
    * @param dispatchFormID
    *
    * Create author:付湘辉 <br>
    * Create on:2009-1-9  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public void checkIsAllowAddBill(Long dispatchFormID){
	   DispatchFormDO dispatchFormDo =  this.dispatchFormDao.findById(dispatchFormID);
	   Boolean isAllow = dispatchFormDo.isAllowAddBill();
	   if (!isAllow) {
		   throw new BusinessException("custservice:custservice_cannot_addbillfordform_exception",
				   				BusinessException.WARNING);
	   }
   }
	
	/**
	    * 功能描述:检查指定的派工单是否允许增加反馈  <br>
	    * @param dispatchFormID
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2009-1-9  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public void checkIsAllowAddFeedback(Long dispatchFormID){
		   DispatchFormDO dispatchFormDo = this.dispatchFormDao.findById(dispatchFormID);
		   Boolean isAllow = dispatchFormDo.isAllowAddFeedback();
		   if (!isAllow) {
				throw new BusinessException("custservice:custservice_dform_cannot_addfeedback_exception",
						BusinessException.WARNING);
		   }
	   }

   /**
    * 功能描述:检查指定的派工单是否允许增加收费项目  <br>
    * @param dispatchFormID 派工单ID
    *
    * Create author:付湘辉 <br>
    * Create on:2009-1-9  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public void checkIsAllowAddServItem(Long dispatchFormID){
	   DispatchFormDO dispatchFormDo = this.dispatchFormDao.findById(dispatchFormID);
	   this.checkDispatchFormAddServItem(dispatchFormDo);
   }

   /** 
	 * 功能描述:检查指定的派工单是否允许删除服务收费项目  <br>
	 * @param dFormID 派工单ID
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2009-1-4  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	public void checkIsAllowDeleteServItem(Long dFormID) {
		   BillVO  billVo = this.custServChargeService.getBillVOByDispatchFormId(dFormID);
		   if (!BlankUtil.isBlank(billVo)) {
			   if (BillDO.BILL_STATUS_TRANSLATE_CODE.equals(billVo.getStatuz())) {
				   throw new BusinessException("custservice:custservice_cannot_deleteitem_hasdelivery_exception",
							BusinessException.WARNING);
			   }
		   }
	}
   
   

	/**
	    * 功能描述:检查指定的派工单是否允许接单登记  <br>
	    * @param dispatchFormID 派工单ID
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2009-1-9  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public void checkIsAllowDispatching(Long dispatchFormID){
		   DispatchFormDO  dispatchFormDo = this.dispatchFormDao.findById(dispatchFormID);
		   if (!dispatchFormDo.isAllowDispatching()) {
			   throw new BusinessException("custservice:custservice_dform_iscomplete_exception",
						BusinessException.WARNING);
		   }
	   }

	/** 
	    * 功能描述:检查指定的派工单是否允许修改服务收费项目  <br>
		 * @param dFormID 派工单ID
		 *
		 * Create author:付湘辉 <br>
		 * Create on:2009-1-4  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		*/
		public void checkIsAllowEditServItem(Long dFormID) {
			   BillVO  billVo = this.custServChargeService.getBillVOByDispatchFormId(dFormID);
			   if (!BlankUtil.isBlank(billVo)) {
				   if (BillDO.BILL_STATUS_TRANSLATE_CODE.equals(billVo.getStatuz())) {
					   throw new BusinessException("custservice:custservice_cannot_edititem_hasdelivery_exception",
								BusinessException.WARNING);
				   }
			   }
		}

	   
	/**
		 * 功能描述:检查指定的派工单是否能作废  <br>
		 * @param dFormID
		 *
		 * Create author:付湘辉 <br>
		 * Create on:2009-1-9  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		 */
		public void checkIsAllowSetAsideDispatchForm(Long dFormID){
			DispatchFormDO  dispatchFormDo = this.dispatchFormDao.findById(dFormID);
			//检查
			Boolean res = dispatchFormDo.checkAllowSetAsideDForm();
			if (!res) {
				throw new BusinessException(
						"custservice:custservice_can_not_edit_dispatch_status",
						BusinessException.WARNING);
			}
		}

	   /**
	    * 功能描述:检查指定的派工单是否允许作废反馈  <br>
	    * @param dispatchFormID
	    * @param feedbackId
	    * 
	    * Create author:付湘辉 <br>
	    * Create on:2009-1-9  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public void checkIsAllowSetAsideFeedback(Long dispatchFormID, Long feedbackId){
		   FeedbackRecord  feedbackDo =  this.dispatchFormDao.getFeedbackRecordById(feedbackId);
		   if (SysrefcodeDO.CONSTANTS_DIGITAL_ZERO.equals(feedbackDo.getValidity())) {
			   throw new BusinessException("custservice:custservice_cannotsetaside_thefeedbackhascancel",
					   BusinessException.WARNING);
		   }

		   DispatchFormDO dispatchFormDo = this.dispatchFormDao.findById(dispatchFormID);
		   //检查
		   Boolean res = dispatchFormDo.isAllowSetAsideFeedback();
		   if (!res) {
			   throw new BusinessException("custservice:custservice_can_not_setasidefeedback",
					   BusinessException.WARNING);
		   }
	   }
	   
	/**
	    * 功能描述: 删除服务项目 <br>
	    * @param dFormID - 派工单ID
	    * @param servItemID - 服务项目ID
	    * @roseuid 49436CAF032C
	    * @return
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2008-12-16  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public Boolean deleteServItem(Long dFormID, Long servItemID) {
		   this.checkIsAllowDeleteServItem(dFormID);
		   DispatchFormDO  dispatchFormDo = this.dispatchFormDao.findById(dFormID);
		   AbstractServiceItem servItem = this.dispatchFormDao.getAbstractServiceItemById(servItemID);
		   //删除
		   dispatchFormDo.removeServItem(servItem);
		   this.dispatchFormDao.updateObject(dispatchFormDo);
		   //统计金额
		   BigDecimal sumAmt = this.sumServItemFee(dispatchFormDo);
		   //通知更新账单
		   this.custServChargeService.noteUpdateBill(dFormID, sumAmt);
		   return true;
	   }

	/**
	    * 功能描述:接单  <br>
	    * @param dFormID - 派工单ID
	    * @param dispatchingVo - 派工单接单Vo对象
	    * @roseuid 49436CAF0251
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2008-12-16  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public DispatchingVO dispatching(Long dFormID, DispatchingVO dispatchingVo) {
		   Assert.notNull(dFormID);
		   Assert.notNull(dispatchingVo);
		   this.checkIsAllowDispatching(dFormID);
		   
		   DispatchFormDO  dispatchFormDo = this.dispatchFormDao.findById(dFormID);
		   checkDateRule(dispatchingVo, dispatchFormDo);
		   Dispatching dispatching = new Dispatching();
		   BeanUtil.convertVoAsDo(dispatchingVo, dispatching);
		   dispatchFormDo.setDispatching(dispatching);
		   //设置状态
		   dispatchFormDo.setStatuzProcessing();
		   this.dispatchFormDao.updateObject(dispatchFormDo);
		   return dispatchingVo;
	   }

	/**
	    * 功能描述: 修改服务项目 <br>
	    *
	    * @param dFormID - 派工单ID
	    * @param servItem - 服务项目
	    * @roseuid 49436CAF030D
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2008-12-17  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   public AbstractServiceItemVO editServItem(Long dFormID, AbstractServiceItemVO servItemVo) {
		   this.checkIsAllowEditServItem(dFormID);
		   //得到一个实例
		   AbstractServiceItem serviceItem = this.generateItemDOByItemVO(servItemVo);
	
		   //装配
		   this.assembleAbstractServiceItemV2D(servItemVo, serviceItem);
		   super.modifyInfo(serviceItem.getSysInfo(), servItemVo.getModifier());
		   servItemVo.setModifyDate(serviceItem.getSysInfo().getModifyDate());
		   DispatchFormDO  dispatchForm = this.dispatchFormDao.findById(dFormID);
	
		   //替换项目
		   dispatchForm.replaceServItem(serviceItem);
	
		   this.dispatchFormDao.updateObject(dispatchForm);
		   //统计金额
		   BigDecimal sumAmt = this.sumServItemFee(dispatchForm);
		   //通知更新账单
		   this.custServChargeService.noteUpdateBill(dFormID, sumAmt);
		   return servItemVo;
	   }

   /**
    * 产生事件编号
    * @return String
    * @roseuid 492527B2008C
    */
   @Deprecated
   public String generateNo() {
	   return null;
   }

   /**
	 * 功能描述: 根据服务费用项目id查询一个服务费用项目VO。 <br>
	 * @param serviceItemId
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public AbstractServiceItemVO getAbstractServiceItemById(Long serviceItemId) {
		Assert.notNull(serviceItemId);
		AbstractServiceItem serviceItem = this.dispatchFormDao.getAbstractServiceItemById(serviceItemId);
		if (BlankUtil.isBlank(serviceItem)) {
			return null;
		}
		AbstractServiceItemVO serviceItemVo = this.generateItemVOByItemDO(serviceItem);
		this.assembleAbstractServiceItemD2V(serviceItem, serviceItemVo);
		return serviceItemVo;
	}

   /**
    * 功能描述: 根据ID查询派工单 <br>
    * @param dFormID - 派工单ID
    * @return DispatchFormVO
    * @roseuid 49436CAF03B9
    * @return
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public DispatchFormVO getDFormByID(Long dFormID) {
	   DispatchFormDO dFormDO = this.dispatchFormDao.findById(dFormID);
	   if (BlankUtil.isBlank(dFormDO)) {
		   return null;
	   }
	   DispatchFormVO dFormVO = new DispatchFormVO();
	   //装配
	   this.assembleD2V(dFormDO, dFormVO);

	   return dFormVO;
   }

   /**
	 * 功能描述: 根据反馈id查询一个派工单反馈。 <br>
	 * @param feedbackRecordId
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public FeedbackRecordVO getFeedbackRecordById(Long feedbackRecordId) {
		FeedbackRecord feedback = this.dispatchFormDao.getFeedbackRecordById(feedbackRecordId);
		if (BlankUtil.isBlank(feedback)) {
			return null;
		}
		FeedbackRecordVO feedbackVO = new FeedbackRecordVO();
		this.assembleFeedbackRecordD2V(feedback, feedbackVO);
		return feedbackVO;
	}

   /**
	 * 功能描述: 打印派工单报表 <br>
	 * @param dForm
	 * @return
	 *
	 * Create author: <br>
	 * Create on:2008-12-25  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo dispatchFormQueryVo)
			throws CEReportException {
		DispatchFormQueryVo dfqvo = (DispatchFormQueryVo)dispatchFormQueryVo;
		Long dFormID = dfqvo.getDispatchFormId();
		Assert.notNull(dFormID);
		DispatchFormVO dispatchFormVo =  this.getDFormByID(dFormID);
		DispatchFormReportVO dispatchFormReportVO=new DispatchFormReportVO();
		//VO值对拷
		BeanUtil.convertVoAsDo(dispatchFormVo, dispatchFormReportVO);
		BeanUtil.convertVoAsDo(dispatchFormVo.getDispatchingVo(), dispatchFormReportVO.getDispatchingVo());
		//接单时间
		dispatchFormReportVO.setReceiveTime(dispatchFormReportVO.getDispatchingVo().getReceiveTime());
		List<AbstractServiceItemVO> ServiceItemList=this.queryServItemListByDFormId(dFormID);
		if(ServiceItemList.size()<5){
			for(int i=ServiceItemList.size();i<5;i++){
				MaterialItemVO materialItemVO=new MaterialItemVO();
				materialItemVO.setPrice(null);
				materialItemVO.setFee(null);
			ServiceItemList.add(materialItemVO);
			}
		}
		dispatchFormReportVO.setAbstractServiceItemSet(ServiceItemList);

		DispatchFormDO dFormDo = this.dispatchFormDao.findById(dFormID);
		SubmitTaskDO task = dFormDo.getSubmitTaskDO();
		if (!BlankUtil.isBlank(task)) {
			CustServiceEventDO eventDo = task.getCustServiceEventDO();
			if (!BlankUtil.isBlank(eventDo)) {
				dispatchFormReportVO.setCustEventKindName(eventDo.getCustomerServiceEventKindDO().getName());
				if (BlankUtil.isBlank(dispatchFormReportVO.getHouseNumber())) {
					dispatchFormReportVO.setFullAddress(eventDo.getFullAddress());
				}
				dispatchFormReportVO.setOwners(eventDo.getOwners());
			}
		}

		List<DispatchFormReportVO> list = new ArrayList<DispatchFormReportVO>();
		list.add(dispatchFormReportVO);
		CEReportDataSet cEReportDataSet=new CEReportDataSet(list);

		return cEReportDataSet;
	}

   /**
	 * 功能描述:查询指定派工单的费用清单金额合计  <br>
	 * @param dispatchFormId
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-29  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public BigDecimal getServItemTotalFee(Long dispatchFormId){
		Assert.notNull(dispatchFormId);
		BigDecimal totalFee = this.dispatchFormDao.getServItemTotalFee(dispatchFormId);
		return totalFee;
	}

   /**
    * 功能描述: 分页查询派工单 <br>
    * @param searchVO
    * @return Page
    * @roseuid 49436CB00000
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   @SuppressWarnings("unchecked")
   public Page queryDFromByPage(DispatchFormSearchVO searchVO) {
	   Assert.notNull(searchVO);
	   searchVO.checkRule();
	   Page page = null;
	   //传入事件ID作为条件，应按事件查询
	   //传入部门ID作为条件，应按部门查询
	   if (!BlankUtil.isBlank(searchVO.getCustEventId())) {
		   page = this.dispatchFormDao.queryDispatchFormEventByPage(searchVO);
	   }else{
		   page = this.dispatchFormDao.queryDispatchFormDeptByPage(searchVO);
	   }
	   List<Object[]> list = page.getResult();
	   List<DispatchFormVO> resList = new ArrayList<DispatchFormVO>();
	   if (!BlankUtil.isBlank(list) && SysrefcodeDO.CONSTANTS_ZERO < list.size()) {
		   synchronized (this) {
			   //初始临时信息
				this.initMapCache();
				for (Iterator<Object[]> iter = list.iterator(); iter.hasNext();) {
					Object[] element = iter.next();
					DispatchFormVO tempVo = new DispatchFormVO();
					//组装VO
					assembleDispatchFormVoByObjectArray(element, tempVo);
					resList.add(tempVo);
				}
				//丢弃临时信息
				this.destoreMapCache();
		   }
		}
	   //重置分页列表
	   page.setResult(resList);
	   return page;
   }

   /**
    * @param searchVO
    * @return List<DispatchFormVO>
    * @roseuid 49436CAF03C8
    */
   @Deprecated
   public List<DispatchFormVO> queryDFromList(SearchVO searchVO) {
	   return null;
   }

	/**
	    * 功能描述: 分页查询反馈登记 <br>
	    * @param searchVO
	    * @return
	    * @roseuid 49436CB0004E
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2008-12-22  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   @SuppressWarnings("unchecked")
	   public Page queryFeedbackRecordByPage(FeedbackSearchVO searchVO) {
		   Assert.notNull(searchVO);
		   searchVO.checkRule();
		   //Dao查询
		   Page page = this.dispatchFormDao.queryFeedbackRecordByPage(searchVO);
		   List<FeedbackRecord> tempList = page.getResult();
	
		   List<FeedbackRecordVO> list = new ArrayList<FeedbackRecordVO>();
		   for (FeedbackRecord record : tempList) {
			   FeedbackRecordVO tempVo = new FeedbackRecordVO();
			   //装配反馈VO
			   this.assembleFeedbackRecordD2V(record, tempVo);
			   list.add(tempVo);
		   }
		   //重置分页列表
		   page.setResult(list);
		   return page;
	   }

   /**
    * 功能描述:分页查询服务项目  <br>
    * @param searchVO
    * @return Page
    * @roseuid 49436CB0003E
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-17  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   @SuppressWarnings("unchecked")
   public Page queryServItemByPage(ServItemSearchVO searchVO) {
	   Assert.notNull(searchVO);
	   searchVO.checkRule();
	   Page page = this.dispatchFormDao.queryServItemByPage(searchVO);
	   List<AbstractServiceItem> servItems = page.getResult();
	   List<AbstractServiceItemVO> servItemVos = new ArrayList<AbstractServiceItemVO>();
	   //转换集合
	   this.convertServiceItemSetD2V(servItems, servItemVos);
	   //重置分页列表
	   page.setResult(servItemVos);
	   return page;
   }

   /**
    * 功能描述: 根据派工单ID查询所有服务费用项目 <br>
    * @param dispatchFormId
    * @return
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-17  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public List<AbstractServiceItemVO> queryServItemListByDFormId(Long dispatchFormId) {
	   List<AbstractServiceItem> servItems = this.dispatchFormDao.queryServItemListByDFormId(dispatchFormId);
	   List<AbstractServiceItemVO> servItemVos = new ArrayList<AbstractServiceItemVO>();
	   //将项目DO集合转成VO集合
	   this.convertServiceItemSetD2V(servItems, servItemVos);
	   return servItemVos;
   }

   /**
    * 功能描述:  处理服务项目,功能说明:
	* <ol>
    * <li> 如果客户端提交的具体一个ServItem实例是新的
    *    (没有被持久化过),那么添加到DO的服务项目集合中.</li>
    * <li> 如果客户端提交的具体一个ServItem实例是游离实
    * 例(曾经被实例化),那么替换DO服务项目集合中的   对应旧实例.</li>
    * <li> 如果在DO中存在的ServItem实例,在客户端本次提
    * 交的List<ServItem>中不存在.则删除DO服务项目   集合中本ServItem实例.</li>
    * </ol>
    * @param dFormID - 派工单ID
    * @param servItems - 服务项目列表
    * @return void
    * @roseuid 49436CAF037A
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author: 付湘辉 <br>
    * Edit on:2008-12-18    <br>
    * Why: 已有其它方法实现，不建议使用此方法，屏蔽接口    <br>
    */
   @Deprecated
   public Boolean servItemMaintain(Long dFormID, List<AbstractServiceItemVO> servItems) {
	   Set<AbstractServiceItemVO> servItemVos = new HashSet<AbstractServiceItemVO>();
	   servItemVos.addAll(servItems);

	   Set<AbstractServiceItem> servItemDoSets = new HashSet<AbstractServiceItem>();
	   this.convertServiceItemSetV2D(servItemVos, servItemDoSets);
	   DispatchFormDO dispatchForm = this.dispatchFormDao.findById(dFormID);

	   dispatchForm.getAbstractServiceItemSet().clear();
	   dispatchForm.getAbstractServiceItemSet().addAll(servItemDoSets);

	   this.dispatchFormDao.updateObject(dispatchForm);
	   return true;
   }
   
   /**
    * 功能描述: 作废派工单 <br>
    * @param dFormID - 派工单ID
    * @roseuid 49436CAF0213
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public Boolean setAsideDForm(Long dFormID,String info) {
	   Assert.notNull(dFormID);
	   if (BlankUtil.isBlank(info)) {
		   throw new BusinessException("custservice:custservice_dform_setaside_remarkisrequired_exception",
					BusinessException.WARNING);
	   }
	   DispatchFormDO  dispatchFormDo = this.dispatchFormDao.findById(dFormID);
	   //检查
	   this.checkIsAllowSetAsideDispatchForm(dFormID);

	   //加入备注信息
	   String remark = dispatchFormDo.getRemark();
	   StringBuilder sb = new StringBuilder(remark==null?"":remark);
	   dispatchFormDo.setRemark(sb.append(" ").append(info).toString());
	   //设置状态
	   dispatchFormDo.setStatuzLogicDelete();
	   SubmitTaskDO submitTaskDO = dispatchFormDo.getSubmitTaskDO();
	   if (!BlankUtil.isBlank(submitTaskDO)) {
		   this.submitTaskService.cancelTaskForDispatch(dispatchFormDo.getSubmitTaskDO().getKeyword());
	   }

	   this.dispatchFormDao.updateObject(dispatchFormDo);
	   return true;
   }

   /**
    * 功能描述:反馈登记作废  <br>
    * @param feedback
    * @roseuid 49436CAF02AF
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-17  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   public Boolean setAsideFeedback(FeedbackRecordVO feedbackVo) {
	   DispatchFormDO dispatchFormDo = this.dispatchFormDao.findById(feedbackVo.getDispatchFormId());
	   //检查
	   this.checkIsAllowSetAsideFeedback(dispatchFormDo.getKeyword(), feedbackVo.getKeyword());

	   FeedbackRecord feedback = this.dispatchFormDao.getFeedbackRecordById(feedbackVo.getKeyword());
	   super.modifyInfo(feedback.getSysInfo(), feedbackVo.getModifier());
	   feedbackVo.setModifyDate(feedback.getSysInfo().getModifyDate());
	   this.assembleFeedbackRecordV2D(feedbackVo, feedback);
	   //设置状态
	   feedback.setValidityFalse();
	   dispatchFormDo.replaceFeedback(feedback);
	   this.dispatchFormDao.updateObject(dispatchFormDo);
	   return true;
   }

   public void setCodingGeneratorService(ICodingGeneratorService codingGeneratorService) {
	   this.codingGeneratorService = codingGeneratorService;
   }

   public void setCustServChargeService(ICustServChargeService custServChargeService) {
	   this.custServChargeService = custServChargeService;
   }

   /**
 * @param custServiceEventDao the custServiceEventDao to set
 */
public void setCustServiceEventDao(ICustServiceEventDao custServiceEventDao) {
	this.custServiceEventDao = custServiceEventDao;
}

   public void setDispatchFormDao(IDispatchFormDao dispatchFormDao) {
	this.dispatchFormDao = dispatchFormDao;
}

   public void setDispatchFormStateMachineService(
		IDispatchFormStateMachineService dispatchFormStateMachineService) {
	this.dispatchFormStateMachineService = dispatchFormStateMachineService;
}

   /**
 * @param emergencyDegreeService the emergencyDegreeService to set
 */
public void setEmergencyDegreeService(
		IEmergencyDegreeService emergencyDegreeService) {
	this.emergencyDegreeService = emergencyDegreeService;
}

   /**
 * @param houseService the houseService to set
 */
public void setHouseService(IHouseService houseService) {
	this.houseService = houseService;
}

   public void setOrganizationalStructureService(
		IOrganizationalStructureService organizationalStructureService) {
	this.organizationalStructureService = organizationalStructureService;
}

   /**
    * @roseuid 49436CAF0196
    */
//   public DFormManageServiceImpl()
//   {
//
//   }

   public void setSubmitTaskService(ISubmitTaskService submitTaskService) {
	   this.submitTaskService = submitTaskService;
   }

   /**
    * 功能描述: 新增一个派工单 <br>
    * @param csEventID
    * @param dForm
    * @param sysInfo
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-23  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
	private void addOneDispatchForm(Long csEventID, DispatchFormVO dForm,SysInfo sysInfo) {
			DispatchFormDO dispatchFormDo = new DispatchFormDO();
			// 装配DO
			this.assembleV2D(dForm, dispatchFormDo);
			dispatchFormDo.setSysInfo(sysInfo);
			//设置派单时间
			dispatchFormDo.setDispatchTime(sysInfo.getSysDate());
			// 生成派工单编号
			String dispatchNo = this.codingGeneratorService
					.generateDispatchFormCoding();
			dispatchFormDo.initDispatchFormNo(dispatchNo);
			// 建立任务
			SubmitTaskVO submitTaskVo = this.autoCreateAnSubmitTask(csEventID,
					dForm);
//			SubmitTaskDO submitTaskDo = new SubmitTaskDO();
			SubmitTaskDO submitTaskDo = this.submitTaskService.getSubmitTaskDOById(submitTaskVo.getKeyword());
//			submitTaskDo.setKeyword(submitTaskVo.getKeyword());
			// 设置任务
			dispatchFormDo.initSubmitTask(submitTaskDo);
			dispatchFormDo.checkRequiredField();
			// 执行保存
			this.dispatchFormDao.saveObject(dispatchFormDo);
			
			this.submitTaskService.noteDeptProcessing(submitTaskVo.getKeyword());

			// 装配VO
			this.assembleD2V(dispatchFormDo, dForm);
	}

   /**
    * 功能描述: 组装一个费用项目VO <br>
    * @param serviceItem
    * @param serviceItemVo
    * @return
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private AbstractServiceItemVO assembleAbstractServiceItemD2V(AbstractServiceItem serviceItem,AbstractServiceItemVO serviceItemVo){
	   Assert.notNull(serviceItem);
	   Assert.notNull(serviceItemVo);

	   BeanUtil.convertVoAsDo(serviceItem,serviceItemVo);

	   DispatchFormDO dispatchFormDO = serviceItem.getDispatchFormDO();
	   if (!BlankUtil.isBlank(dispatchFormDO)) {
		   serviceItemVo.setDispatchFormId(dispatchFormDO.getKeyword());
	   }

	   if (!BlankUtil.isBlank(serviceItem.getSysInfo())) {
		   BeanUtil.convertVoAsDo(serviceItem.getSysInfo(),serviceItemVo);
	   }
	   return serviceItemVo;
   }

   /**
    * 功能描述: 组装一个费用项目DO <br>
    * @param serviceItemVo
    * @param serviceItem
    * @return
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private AbstractServiceItem assembleAbstractServiceItemV2D(AbstractServiceItemVO serviceItemVo,AbstractServiceItem serviceItem){
	   Assert.notNull(serviceItemVo);
	   Assert.notNull(serviceItem);

	   BeanUtil.convertVoAsDo(serviceItemVo, serviceItem);

	   DispatchFormDO dispatchFormDO = this.dispatchFormDao.loadById(serviceItemVo.getDispatchFormId());
	   serviceItem.setDispatchFormDO(dispatchFormDO);
	   this.calculateItemFee(serviceItem, serviceItemVo);
	   return serviceItem;
   }

   /**
    * 功能描述: 转换DO 到 VO <br>
    * @param dFormDO - 派工单DO
    * @param dFormVO - 派工单VO
    * @return DispatchFormVO
    * @roseuid 492526940399
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private DispatchFormVO assembleD2V(DispatchFormDO dFormDO, DispatchFormVO dFormVO) {
	   Assert.notNull(dFormDO);
	   Assert.notNull(dFormVO);

	   BeanUtil.convertVoAsDo(dFormDO, dFormVO);
	   HouseDomain house = dFormDO.getHouse();
	   if (!BlankUtil.isBlank(house)) {
		   dFormVO.setHouseId(house.getKeyword());
		   dFormVO.setHouseNumber(house.getHouseNumber());
	   }

	   EmergencyDegreeDO emergencyDegree = dFormDO.getEmergencyDegreeDO();
	   if (!BlankUtil.isBlank(emergencyDegree)) {
		   dFormVO.setEmergencyDegreeId(emergencyDegree.getKeyword());
		   dFormVO.setEmergencyDegreeName(emergencyDegree.getName());
	   }

	   HmDeptDomain dept = dFormDO.getDeptDO();
	   if (!BlankUtil.isBlank(dept)) {
		   dFormVO.setDeptId(dept.getDeptId());
		   dFormVO.setDeptName(dept.getDeptName());
	   }

	   SubmitTaskDO task = dFormDO.getSubmitTaskDO();
	   if (!BlankUtil.isBlank(task)) {
		   dFormVO.setTaskId(task.getKeyword());
		   CustServiceEventDO cEvent = task.getCustServiceEventDO();
		   dFormVO.setFullAddress(cEvent.getFullAddress());
	   }

	   SysInfo sysInfo = dFormDO.getSysInfo();
	   if (!BlankUtil.isBlank(sysInfo)) {
		   BeanUtil.convertVoAsDo(sysInfo, dFormVO);
	   }

	   Dispatching dispatching = dFormDO.getDispatching();
	   if (!BlankUtil.isBlank(dispatching)) {
		   BeanUtil.convertVoAsDo(dispatching, dFormVO.getDispatchingVo());
	   }

	   return dFormVO;
   }

   /**
    * 功能描述:  <br>
    * @param element
    * @param tempVo
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-19  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
	private void assembleDispatchFormVoByObjectArray(Object[] element, DispatchFormVO tempVo) {
//		派工单ID
		tempVo.setKeyword(element[0]==null?null:((BigInteger)element[0]).longValue());
//		派工单号
		tempVo.setDispatchNo(element[1]==null?null:((String)element[1]));
//		房号
		   tempVo.setHouseNumber(element[2]==null?null:((String)element[2]));
//		 服务内容
		   tempVo.setServiceContent(element[3]==null?null:((String)element[3]));
//		 联系人
		   tempVo.setContact(element[4]==null?null:((String)element[4]));
//		 部门ID
		   Long deptId = element[5]==null?null:((BigInteger)element[5]).longValue();
		   tempVo.setDeptId(deptId);
		   if (BlankUtil.isBlank(this.deptNameCacheMap.get(deptId))) {
			   this.deptNameCacheMap.put(deptId, this.organizationalStructureService.getDeptNameById(deptId));
		   }
//		 部门名称
		   tempVo.setDeptName(this.deptNameCacheMap.get(deptId));
//		 紧急程度显示名字
		   tempVo.setEmergencyDegreeName(element[6]==null?null:((String)element[6]));
//		 开工时间
		   tempVo.setStartTime(element[7]==null?null:((Date)element[7]));
//		 完工时间
		   tempVo.setEndTime(element[8]==null?null:((Date)element[8]));
//		 状态编码如：001
		   String statuzCode = element[9]==null?null:((String)element[9]);
		   tempVo.setStatuz(statuzCode);
//		 状态显示名字
		   tempVo.setStatuName(this.dispatchFormStateCacheMap.get(statuzCode));
//		 创建者ID
		   tempVo.setCreator(element[10]==null?null:((BigInteger)element[10]).longValue());
//		 任务ID
		   tempVo.setTaskId(element[11]==null?null:((BigInteger)element[11]).longValue());
//		 事件ID
		   //tempVo.setEventId(element[12]==null?null:((BigInteger)element[12]).longValue());
//		 房屋ID
		   tempVo.setHouseId(element[13]==null?null:((BigInteger)element[13]).longValue());
//		 详细地址
		   tempVo.setFullAddress(element[14]==null?null:(String)element[14]);
	}

   /**
    * 功能描述: 反馈登记D2V <br>
    * @param feedbackVO
    * @param feedback
    * @return FeedbackRecordVO
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private FeedbackRecordVO assembleFeedbackRecordD2V(FeedbackRecord feedback,FeedbackRecordVO feedbackVO) {
	   Assert.notNull(feedback);
	   Assert.notNull(feedbackVO);

	   BeanUtil.convertVoAsDo(feedback,feedbackVO);
	   //部门
	   HmDeptDomain deptDO = feedback.getDeptDO();
	   if (!BlankUtil.isBlank(deptDO)) {
		   feedbackVO.setDeptId(deptDO.getDeptId());
		   feedbackVO.setDeptName(deptDO.getDeptName());
	   }

	   //派工单
	   DispatchFormDO dispatchForm=feedback.getDispatchForm();
	   if (!BlankUtil.isBlank(dispatchForm)) {
		   feedbackVO.setDispatchFormId(dispatchForm.getKeyword());
		   feedbackVO.setDispatchNo(dispatchForm.getDispatchNo());
		   feedbackVO.setStartTime(dispatchForm.getStartTime());
		   feedbackVO.setEndTime(dispatchForm.getEndTime());
	   }

	   if (!BlankUtil.isBlank(feedback.getSysInfo())) {
		   BeanUtil.convertVoAsDo(feedback.getSysInfo(),feedbackVO);
	   }
	   return feedbackVO;
   }

   /**
    * 功能描述: 反馈登记V2D <br>
    * @param feedbackVO
    * @param feedback
    * @roseuid 49420FDE032C
    * @return FeedbackRecord
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private FeedbackRecord assembleFeedbackRecordV2D(FeedbackRecordVO feedbackVO, FeedbackRecord feedback) {
	   Assert.notNull(feedbackVO);
	   Assert.notNull(feedback);

	   BeanUtil.convertVoAsDo(feedbackVO, feedback);
	   //部门
	   if (!BlankUtil.isBlank(feedbackVO.getDeptId())) {
//		   HmDeptDomain deptDO = new HmDeptDomain();
		   HmDeptDomain deptDO = this.organizationalStructureService.getHmDeptDomainById(feedbackVO.getDeptId());
//		   deptDO.setDeptId(feedbackVO.getDeptId());
		   feedback.setDeptDO(deptDO);
	   }

	   //派工单
	   DispatchFormDO dispatchForm=this.dispatchFormDao.loadById(feedbackVO.getDispatchFormId());
	   feedback.setDispatchForm(dispatchForm);

	   return feedback;
   }
/**
    * 功能描述: 转换派工单VO 到 DO <br>
    * @param dFormVO - 派工单VO
    * @param dFormDO - 派工单DO
    * @return DispatchFormDO
    * @roseuid 4925269403B9
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-16  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private DispatchFormDO assembleV2D(DispatchFormVO dFormVO, DispatchFormDO dFormDO) {
	   Assert.notNull(dFormVO);
	   Assert.notNull(dFormDO);
//	   String[] ignores=new String[]{"statuz"};
//	   BeanUtil.convertVoAsDo(dFormVO, dFormDO,ignores);
	   BeanUtil.convertVoAsDo(dFormVO, dFormDO);
	   //紧急程度
	   if (!BlankUtil.isBlank(dFormVO.getEmergencyDegreeId())) {
//		   EmergencyDegreeDO eddo = new EmergencyDegreeDO();
		   EmergencyDegreeDO eddo = this.emergencyDegreeService.getEmergencyDegreeDOById(dFormVO.getEmergencyDegreeId());
//		   eddo.setKeyword(dFormVO.getEmergencyDegreeId());
		   dFormDO.setEmergencyDegreeDO(eddo);
	   }

	   //房屋
	   if (!BlankUtil.isBlank(dFormVO.getHouseId())) {
//		   HouseDomain house = new HouseDomain();
		   HouseDomain house = this.houseService.getHouseById(dFormVO.getHouseId());
//		   house.setKeyword(dFormVO.getHouseId());
		   dFormDO.setHouse(house);
	   }

	   //部门
	   if (!BlankUtil.isBlank(dFormVO.getDeptId())) {
//		   HmDeptDomain deptDO = new HmDeptDomain();
		   HmDeptDomain deptDO = this.organizationalStructureService.getHmDeptDomainById(dFormVO.getDeptId());
//		   deptDO.setDeptId(dFormVO.getDeptId());
		   dFormDO.setDeptDO(deptDO);
	   }

	   return dFormDO;
   }
/**
    * 功能描述: 主动提交一个任务,初始化sumbitTaskVO规则: <br>
    * <ol>
    * <li>根据参数csEventID设置事件ID csEventID.</li>
    * <li>根据dForm中的接单部门设置执行部门dept.</li>
    * <li>根据dForm中的接单人设置执行人deptPrincipal;</li>
    * </ol>
    * @param csEventID - 客服事件ID
    * @param dFrom - 派工单VO
    * @return SubmitTaskVO
    * @roseuid 4943497201C5
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-23  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private SubmitTaskVO autoCreateAnSubmitTask(Long csEventID, DispatchFormVO dForm) {
	   SubmitTaskVO submitTaskVo = new SubmitTaskVO();
	   submitTaskVo.setCustServiceEventId(csEventID);
	   submitTaskVo.setDeptId(dForm.getDeptId());
	   submitTaskVo.setDeptPrincipalName(dForm.getReceiver());
	   submitTaskVo.setCreator(dForm.getCreator());
//	   submitTaskVo.setDeptPrincipalId(dForm.getCreator());
	   submitTaskVo = this.submitTaskService.autoAddTask(csEventID, submitTaskVo);
	   return submitTaskVo;
   }

   /**
    * 功能描述:计算金额  <br>
 * @param serviceItem
    *
    * Create author:付湘辉 <br>
    * Create on:2008-12-17  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
 * @param serviceItemVo
    */
	private void calculateItemFee(AbstractServiceItem serviceItem, AbstractServiceItemVO serviceItemVo) {
		   //金额=单价 * 实际使用量
			if (!BlankUtil.isBlank(serviceItem.getPrice())) {
				BigDecimal fee = BigDecimalUtil.getZEROInstance();
				if (BlankUtil.isBlank(serviceItem.getCustomerUsage())) {
				// 什么都不做
				}else{
					fee = serviceItem.getPrice().multiply(
						new BigDecimal(serviceItem.getCustomerUsage().longValue()),
													BigDecimalUtil.getMathContext());
				}
				
				serviceItem.setFee(fee);
				//计算后写到VO中
				serviceItemVo.setFee(fee);
			}
	}

   /** 功能描述:检查派单时间与接单登记的时间规则  <br>
 * @param dispatchingVo
 * @param dispatchFormDo
 *
 * Create author:付湘辉 <br>
 * Create on:2009-1-12  <br>
 * Edit author:  <br>
 * Edit on:    <br>
 * Why:     <br>
*/
private void checkDateRule(DispatchingVO dispatchingVo, DispatchFormDO dispatchFormDo) {
	//得到派单时间
	Date dispatchTime = dispatchFormDo.getDispatchTime();
	//得到接单时间
	Date receiveTime = dispatchingVo.getReceiveTime();
	if (!BlankUtil.isBlank(dispatchTime) && !BlankUtil.isBlank(receiveTime)) {
		if (receiveTime.before(dispatchTime)) {
			throw new BusinessException("custservice:custservice_cannotdispatching_date_exception",
					BusinessException.WARNING);
		}
	}
}

	/** 功能描述:  <br>
		 * @param dispatchForm
		 *
		 * Create author:付湘辉 <br>
		 * Create on:2009-1-4  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		*/
		private void checkDispatchFormAddServItem(DispatchFormDO dispatchForm) {
			if (!(DispatchFormDO.DISPATCH_STATUS_NEW_CODE.equals(dispatchForm.getStatuz())
					   		|| DispatchFormDO.DISPATCH_STATUS_HANDLING_CODE.equals(dispatchForm.getStatuz()))) {
				   throw new BusinessException("custservice:custservice_cannot_additem_statuz_exception",
							BusinessException.WARNING);
		   	}
			BillVO billVo=this.custServChargeService.getBillVOByDispatchFormId(dispatchForm.getKeyword());
			if (!BlankUtil.isBlank(billVo)) {
				if (BillDO.BILL_STATUS_TRANSLATE_CODE.equals(billVo.getStatuz())) {
					throw new BusinessException("custservice:custservice_cannotadditem_statuzhasdelivery_exception",
							BusinessException.WARNING);
				}
			}
		}

	   /** 功能描述:  <br>
	 * @param feedback
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2009-1-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private void checkFeedbackRequiredField(FeedbackRecord feedback) {
		if (BlankUtil.isBlank(feedback.getContent())
				   || BlankUtil.isBlank(feedback.getHasComplete())
				   || BlankUtil.isBlank(feedback.getDispatchForm())
				   || BlankUtil.isBlank(feedback.getSysInfo())
				   || BlankUtil.isBlank(feedback.getSysInfo().getCreator())
				   || BlankUtil.isBlank(feedback.getSysInfo().getSysDate())) {
			   throw new BusinessException("common:mustFill_null_exception",
						BusinessException.WARNING);
		   }
	}

   /**
    * 功能描述:检查派工单开工时间和完工时间，当反馈已完工时调用。  <br>
    * @param dispatchFormDo
    *
    * Create author:付湘辉 <br>
    * Create on:2009-1-4  <br>
    * Edit author:  <br>
    * Edit on:    <br>
    * Why:     <br>
    */
   private void checkStartTimeAndEndTime(DispatchFormDO dispatchFormDo) {
	   if (dispatchFormDo.isDFormComplete()) {
		   if (BlankUtil.isBlank(dispatchFormDo.getEndTime())) {
			   throw new BusinessException("custservice:custservice_not_endtime_exception",
					   BusinessException.WARNING);
		   }

		   if (!BlankUtil.isBlank(dispatchFormDo.getStartTime()) && dispatchFormDo.getStartTime().after(dispatchFormDo.getEndTime())) {
			   throw new BusinessException("custservice:custservice_starttiem_after_endtime_exception",
					   BusinessException.WARNING);
		   }
	   }

	   if (!BlankUtil.isBlank(dispatchFormDo.getStartTime()) && !BlankUtil.isBlank(dispatchFormDo.getDispatchTime())) {
		   if (dispatchFormDo.getStartTime().before(dispatchFormDo.getDispatchTime())) {
			   throw new BusinessException("custservice:custservice_starttiem_before_dispatchtime_exception",
					   BusinessException.WARNING);
		   }
	   }
   }

	/**
	    * 功能描述: 转换一个AbstractServiceItem集合为AbstractServiceItemVO集合 <br>
	    * @param servItems
	    * @param servItemVos
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2008-12-16  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   private void convertServiceItemSetD2V(Collection<AbstractServiceItem> servItems, Collection<AbstractServiceItemVO> servItemVos){
		   Assert.notNull(servItemVos);
		   if (!BlankUtil.isBlank(servItems)) {
			   for (Iterator<AbstractServiceItem> iter = servItems.iterator(); iter.hasNext();) {
				   AbstractServiceItem element = iter.next();
				   AbstractServiceItemVO asItem = generateItemVOByItemDO(element);
				   this.assembleAbstractServiceItemD2V(element, asItem);
				   servItemVos.add(asItem);
			   }
		   }
	   }

	/**
	    * 功能描述: 转换一个AbstractServiceItemVO集合为AbstractServiceItem集合 <br>
	    * @param servItemVos
	    * @param servItems
	    *
	    * Create author:付湘辉 <br>
	    * Create on:2008-12-16  <br>
	    * Edit author:  <br>
	    * Edit on:    <br>
	    * Why:     <br>
	    */
	   private void convertServiceItemSetV2D(Collection<AbstractServiceItemVO> servItemVos,Collection<AbstractServiceItem> servItems){
		   Assert.notNull(servItems);
		   if (!BlankUtil.isBlank(servItemVos)) {
			   for (Iterator<AbstractServiceItemVO> iter = servItemVos.iterator(); iter.hasNext();) {
				   AbstractServiceItemVO element = iter.next();
				   AbstractServiceItem asItem = generateItemDOByItemVO(element);
				   this.assembleAbstractServiceItemV2D(element, asItem);
				   servItems.add(asItem);
			   }
		   }
	   }

   /**
	 * 功能描述:  <br>
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-17  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
   private void destoreMapCache(){
		this.hmployeeNameCacheMap = null;
		this.dispatchFormStateCacheMap = null;
		this.deptNameCacheMap=null;
   }

	/**
		 * 功能描述: 根据所给VO的实例生成一个对应的DO <br>
		 * @param instance
		 * @return
		 *
		 * Create author:付湘辉 <br>
		 * Create on:2008-12-17  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		 */
		private AbstractServiceItem generateItemDOByItemVO(AbstractServiceItemVO instance) {
			Assert.notNull(instance);
			if (!BlankUtil.isBlank(instance.getKeyword())) {
				return this.dispatchFormDao.getAbstractServiceItemById(instance
									.getKeyword());
			}

			if (instance instanceof MaterialItemVO) {
				return new MaterialItem();
			} else if (instance instanceof LaborItemVO) {
				return new LaborItem();
			}
			return null;
		}

		/**
		 * 功能描述: 根据所给DO的实例生成一个对应的VO <br>
		 *
		 * @param instance
		 * @return
		 *
		 * Create author:付湘辉 <br>
		 * Create on:2008-12-17 <br>
		 * Edit author: <br>
		 * Edit on: <br>
		 * Why: <br>
		 */
		private AbstractServiceItemVO generateItemVOByItemDO(AbstractServiceItem instance) {
			Assert.notNull(instance);
			if (instance instanceof MaterialItem) {
			   return new MaterialItemVO();
			}else if (instance instanceof LaborItem) {
			   return new LaborItemVO();
			}
			return null;
		}

	   /**
	 * 功能描述:初始化派工单状态value与name键值对临时缓存  <br>
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-23  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
   private void initDispatchFormStateMap(){
	   this.dispatchFormStateCacheMap = new HashMap<String, String>();
	   List<SysrefcodeDO> list = this.sysrefcodeDao.querySysrefCodesByCode(SysrefcodeDO.CE_DISPATCH_FORM_STATUZ_CODE);
	   for (Iterator<SysrefcodeDO> iter = list.iterator(); iter.hasNext();) {
		   SysrefcodeDO element = iter.next();
		   this.dispatchFormStateCacheMap.put(
								   element.getValue(),
								   element.getName());
	   }
   }

	/**
		 * 功能描述: 初始化临时数据 <br>
		 *
		 *
		 * Create author:付湘辉 <br>
		 * Create on:2008-11-27  <br>
		 * Edit author:  <br>
		 * Edit on:    <br>
		 * Why:     <br>
		 */
		private void initMapCache(){
			this.initDispatchFormStateMap();
	//		this.hmployeeNameCacheMap = new HashMap<Long, String>();
			this.deptNameCacheMap = new HashMap<Long, String>();
		}

	/**
	    * 处理服务项目,功能说明:
	    * 1. 如果客户端提交的具体一个ServItem实例是新的
	    *    (没有被持久化过),那么添加到DO的服务项目集合   中.
	    * 2. 如果客户端提交的具体一个ServItem实例是游离实
	    * 例(曾经被实例化),那么替换DO服务项目集合中的   对应旧实例.
	    * 3. 如果在DO中存在的ServItem实例,在客户端本次提
	    * 交的List<ServItem>中不存在.则删除DO服务项目   集合中本ServItem实例.
	    * @roseuid 493654620399
	    */
		@SuppressWarnings("unused")
		@Deprecated
	   private void processServItem() {

	   }

	/**
	 * 功能描述: 计算DO服务项目集合的总金额,规则: sum all (单价*数量) <br>
	 * @param dForm
	 * @return
	 * @roseuid 493658C2035B
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-17  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
   private BigDecimal sumServItemFee(DispatchFormDO dForm) {
	   Assert.notNull(dForm);
	   BigDecimal amt = BigDecimalUtil.getZEROInstance();
	   Set<AbstractServiceItem>serviceItems = dForm.getAbstractServiceItemSet();
	   for (Iterator<AbstractServiceItem> iter = serviceItems.iterator(); iter.hasNext();) {
		   AbstractServiceItem element = iter.next();
		   amt = amt.add(element.getFee().setScale(SysrefcodeDO.DATA_PRICE_SCALE));
	   }
	   return amt;
   }
}
